<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .demo {
            position: relative;
            top:100px;
            left: 100px;
            width:100px;
        }
    </style>
</head>
<body>
    <div class="demo"></div>
    <script>
        document.querySelector('.demo').textContent = new Date().toLocaleTimeString();
        // setInterval
        function displayTime() {
            let time = new Date().toLocaleTimeString();
            document.querySelector('.demo').textContent = time;
            window.requestAnimationFrame(displayTime)
        }
        // setInterval(displayTime,1000)

        // requestAnimationFrame
        displayTime()

        const spinner = document.querySelector('div');
        let rotateCount = 0;
        let startTime = null;
        let rAF;

        function draw(timestamp) {
        if(!startTime) {
            startTime = timestamp;
        }

        let rotateCount = (timestamp - startTime) / 3;

        spinner.style.transform = 'rotate(' + rotateCount + 'deg)';

        if(rotateCount > 359) {
            rotateCount = 0;
        }

        rAF = requestAnimationFrame(draw);
        }

        draw();
    </script>
</body>
</html>